package com.bizihang.common.security.core.authentication;

import com.bizihang.common.security.core.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

/**
 * 表单登录配置
 *
 * @author 毕子航 951755883@qq.com
 * @date 2018/10/21
 */
@Component
public class FormAuthenticationSecurityConfig {
	/**
	 * pc端认证成功处理器
	 */
	@Autowired
	protected AuthenticationSuccessHandler authenticationSuccessHandler;

	/**
	 * pc端认证失败处理器
	 */
	@Autowired
	protected AuthenticationFailureHandler authenticationFailureHandler;


	/**
	 * 表单登陆配置
	 *
	 * @param http
	 * @throws Exception
	 */
	public void configure(HttpSecurity http) throws Exception {
		http.formLogin()
				.loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)
				.loginProcessingUrl(SecurityConstants.DEFAULT_SIGN_IN_PROCESSING_URL_FORM)
				.successHandler(authenticationSuccessHandler)
				.failureHandler(authenticationFailureHandler);
	}
}
